package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.DishDto;

import com.itheima.reggie.entity.Dish;

import com.itheima.reggie.service.DishFlavorService;
import com.itheima.reggie.service.DishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:test
 * @Create by: CAt
 * @Date;2021/9/2921:01
 */
@Slf4j
@RestController
@RequestMapping("/dish")
public class DishFlavorController {

    @Autowired
    private DishService dishService;
    @Autowired
    private DishFlavorService dishFlavorService;

    //菜品分页
    @GetMapping("/page")
    public R fenye(Integer page,Integer pageSize){
        LambdaQueryWrapper<Dish> querWra=new LambdaQueryWrapper<>();
        IPage<Dish> pageee=new Page<>(page,pageSize);
        querWra.orderByDesc(Dish::getUpdateTime);
        IPage<Dish> page1 = dishService.page(pageee, querWra);
        return R.success(page1);
    }
    //菜品添加
    @PostMapping
    public R caipingtianjia(@RequestBody DishDto dishDto){
             dishService.tianjia(dishDto);
        return R.success("添加成功");
    }

    //菜品回显
    @GetMapping("/{id}")
    public R caipingxiugai(@PathVariable("id") Long id){
        log.info(id.toString());
        DishDto xiugai = dishService.xiugai(id);
        return R.success(xiugai);
    }

    //菜品回显后保存
  @PutMapping
    public  R huixianbaocun(@RequestBody DishDto dishDto){
        dishService.huixianxiugai(dishDto);
        return R.success("修改成功");
  }

  //套餐中添加菜品
    @GetMapping("/list")
    public  R caiping(Dish dish){
     log.info(dish.getCategoryId().toString());
        LambdaQueryWrapper<Dish> qewss=new LambdaQueryWrapper<>();
        qewss.eq(dish.getCategoryId()!=null,Dish::getCategoryId,dish.getCategoryId());
        qewss.eq(Dish::getStatus,1);
        List<Dish> list = dishService.list(qewss);
        return R.success(list);

    }
  //菜品的批量停售和起售
    @PostMapping("/status/{id}")
    public R piliangtingshou(@PathVariable Integer id, List<Long> ids){
log.info(id.toString());
log.info(ids.toString());
        return null;
    }
}
